home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.border;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Insets;
-
- public class BevelBorder extends AbstractBorder {
- public static final int RAISED = 0;
- public static final int LOWERED = 1;
- protected int bevelType;
- protected Color highlightOuter;
- protected Color highlightInner;
- protected Color shadowInner;
- protected Color shadowOuter;
-
- public BevelBorder(int bevelType) {
- this.bevelType = bevelType;
- }
-
- public BevelBorder(int bevelType, Color highlight, Color shadow) {
- this(bevelType, highlight.darker(), highlight, shadow, shadow.brighter());
- }
-
- public BevelBorder(int bevelType, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
- this(bevelType);
- this.highlightOuter = highlightOuter;
- this.highlightInner = highlightInner;
- this.shadowOuter = shadowOuter;
- this.shadowInner = shadowInner;
- }
-
- public int getBevelType() {
- return this.bevelType;
- }
-
- public Insets getBorderInsets(Component c) {
- return new Insets(2, 2, 2, 2);
- }
-
- public Color getHighlightInnerColor(Component c) {
- return this.highlightInner != null ? this.highlightInner : c.getBackground().brighter();
- }
-
- public Color getHighlightOuterColor(Component c) {
- return this.highlightOuter != null ? this.highlightOuter : c.getBackground().brighter().brighter();
- }
-
- public Color getShadowInnerColor(Component c) {
- return this.shadowInner != null ? this.shadowInner : c.getBackground().darker();
- }
-
- public Color getShadowOuterColor(Component c) {
- return this.shadowOuter != null ? this.shadowOuter : c.getBackground().darker().darker();
- }
-
- public boolean isBorderOpaque() {
- return true;
- }
-
- public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
- if (this.bevelType == 0) {
- this.paintRaisedBevel(c, g, x, y, width, height);
- } else if (this.bevelType == 1) {
- this.paintLoweredBevel(c, g, x, y, width, height);
- }
-
- }
-
- protected void paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height) {
- Color oldColor = g.getColor();
- g.translate(x, y);
- g.setColor(this.getShadowInnerColor(c));
- g.drawLine(0, 0, 0, height - 1);
- g.drawLine(1, 0, width - 1, 0);
- g.setColor(this.getShadowOuterColor(c));
- g.drawLine(1, 1, 1, height - 2);
- g.drawLine(2, 1, width - 2, 1);
- g.setColor(this.getHighlightOuterColor(c));
- g.drawLine(1, height - 1, width - 1, height - 1);
- g.drawLine(width - 1, 1, width - 1, height - 2);
- g.setColor(this.getHighlightInnerColor(c));
- g.drawLine(2, height - 2, width - 2, height - 2);
- g.drawLine(width - 2, 2, width - 2, height - 3);
- g.translate(-x, -y);
- g.setColor(oldColor);
- }
-
- protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) {
- Color oldColor = g.getColor();
- g.translate(x, y);
- g.setColor(this.getHighlightOuterColor(c));
- g.drawLine(0, 0, 0, height - 1);
- g.drawLine(1, 0, width - 1, 0);
- g.setColor(this.getHighlightInnerColor(c));
- g.drawLine(1, 1, 1, height - 2);
- g.drawLine(2, 1, width - 2, 1);
- g.setColor(this.getShadowOuterColor(c));
- g.drawLine(1, height - 1, width - 1, height - 1);
- g.drawLine(width - 1, 1, width - 1, height - 2);
- g.setColor(this.getShadowInnerColor(c));
- g.drawLine(2, height - 2, width - 2, height - 2);
- g.drawLine(width - 2, 2, width - 2, height - 3);
- g.translate(-x, -y);
- g.setColor(oldColor);
- }
- }
-